/**
 * 
 * Copyright (C) 2011 Cody Stoutenburg . All rights reserved.
 *
 *       This program is free software; you can redistribute it and/or
 *       modify it under the terms of the GNU Lesser General Public License
 *       as published by the Free Software Foundation; either version 2.1
 *       of the License, or (at your option) any later version.
 *
 *       This program is distributed in the hope that it will be useful,
 *       but WITHOUT ANY WARRANTY; without even the implied warranty of
 *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *       GNU Lesser General Public License for more details.
 *
 *       You should have received a copy of the GNU Lesser General Public License
 *       along with this program; if not, write to the Free Software
 *       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
 * 
 */
package ca.usherbrooke.agent.controller.shared;

import java.io.Serializable;

import ca.usherbrooke.model.entity.IEntityModel;

/**
 * @author Cody Stoutenburg
 * 
 */
public abstract class IBehaviour<E extends IAgent> implements Serializable {
	private static final long serialVersionUID = 1L;

	private final E agent;

	public IBehaviour(E agent) {
		this.agent = agent;
	}

	protected E getAgent() {
		return agent;
	}

	/**
	 * 
	 * @return the entity of the agent
	 */
	protected IEntityModel getEntity() {
		return getAgent().getEntity();
	}

	/**
	 * Runs the behaviour. This abstract method must be implemented by
	 * IBehaviourOnWorldChanged to perform ordinary behaviour duty. An agent
	 * schedules its behaviours calling their action() method; since all the
	 * behaviours belonging to the same agent are scheduled cooperatively, this
	 * method must not enter in an endless loop and should return as soon as
	 * possible to preserve agent responsiveness. To split a long and slow task
	 * into smaller section, recursive behaviour aggregation may be used.
	 */
	public abstract void action();

	/**
	 * Check if this behaviour is done. The agent scheduler calls this method to
	 * see whether a Behaviour still need to be run or it has completed its
	 * task. Concrete behaviours must implement this method to return their
	 * completion state. Finished behaviours are removed from the scheduling
	 * queue, while others are kept within to be run again when their turn comes
	 * again.
	 * 
	 * @Returns: true if the behaviour has completely executed.
	 */
	public abstract boolean done();
}
